import java.io.Serializable;
import java.util.Calendar;
import java.util.Locale;


public class Invoice implements Serializable {

	private String invoice_number;
	static int id_next = 0;
	private Klient zamawiajacy;
	private Order order; //ca�o�� w kompozycji z faktur�
	
	
	private Invoice(Klient klient, Order aOrder){
		invoice_number = nextID();
		zamawiajacy = klient;
		order =aOrder; 
	}
	
	
	//Zwraca faktur�, gdy istnieje zam�wienie 
	
	public static Invoice getInvoice(Order aOrder) throws Exception{
		
		//if(!(aOrder.getInvoice() == null)) throw new Exception("Zam�wienie ma ju� powi�zan� faktur�");
		
		Invoice in = new Invoice(aOrder.getClient(), aOrder);
		aOrder.setInvoice(in);
		
		return null;
	}
	
	//Genaretes unique invoice_number based on current date 
	private String nextID() {
		String r =""+Calendar.getInstance(new Locale("PL")).get(Calendar.YEAR)+"\\"
					+Calendar.getInstance(new Locale("PL")).get(Calendar.MONTH)+"\\"
					+Calendar.getInstance(new Locale("PL")).get(Calendar.DAY_OF_MONTH)+"\\"
					+ ++id_next;
		
		return r;
		
	}

	
	public String getId() {
		return invoice_number;
	}


	public Klient getZamawiajacy() {
		return zamawiajacy;
	}

	@Override
	public String toString(){
		return "Faktura nr: "+invoice_number;
	}

	public static void main(String[] args) {

	}

}
